package com.ccpdown.adapter;

import java.util.List;

import com.ccpdown.layout.SoftListLayout;
import com.ccpdown.util.StringUtil;
import com.ccpdown.util.show.BitmapDownloader;
import com.ccpdown.view.R;
import com.ccpdown.vo.Software;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public class SoftListAdapter extends BaseAdapter {

	private Context context;
	private List<Software> item;

	public SoftListAdapter(Context context) {
		this.context = context;
	}

	public void setItem(List list) {
		this.item = list;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return this.item.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return item.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		SoftListLayout btv;
		if (convertView == null) {
			btv = new SoftListLayout(context, item.get(position));
		} else { // Reuse/Overwrite the View passed
			// We are assuming(!) that it is castable!
			btv = (SoftListLayout) convertView;
		}
		if (item.get(position).icon != null) {
			BitmapDownloader.setSocketImg(btv.ivSoftIcon,
					item.get(position).iconPath, context.getResources()
							.getDrawable(R.drawable.defaulticon));
		} else {
			btv.setIvSoftIcon(context.getResources().getDrawable(
					R.drawable.defaulticon));
		}
		btv.setTvSoftName(item.get(position).getSoftName());
		btv.setTvWrite(item.get(position).getWriter());
		btv.setTvSoftSq(StringUtil.getSoftSq(item.get(position).getSoftSq()));
		// btv.setIvStart(item.get(position).getSoftStart());
		return btv;
	}

}
